//@ts-nocheck

window.gameStart = ()=>{
  console.log("Start咯");
};
window.gameClose = ()=>{
  console.log("End咯");
};
window.advChannels = '{{__adv_channels_adapter__}}'
export class AdsManager  {

  async init(){
    console.log("广告SDK开始Init:  "+window.advChannels);
    switch(window.advChannels)
    {
      case 'IronSource':
        this.sdk = await import("./IronSourceAds");
        break;
      case 'AppLovin':
        this.sdk = await import("./AppLovinAds");
        break;
      case 'Mintegral':
        this.sdk = await import("./MintegralAds");
        break;
      default:
        this.sdk = await import("./PCAds");
        break;
    }
    this.sdk.init();
    this.sdk.gameStart();
  }
  
  redirect() {
    console.log("download");
    this.sdk.openStoreUrl();
    //@ts-ignore
    if (typeof redirectStore !== "undefined") redirectStore();
  }

  end(){
    this.sdk?.gameEnd();
  }

  /**
   * Game start method for Mintegral channel.
   */
  gameStart() {
    console.log("game start");
    //@ts-ignore
    if (typeof onGameReady !== "undefined") onGameReady();

    //@ts-ignore
    if (typeof startGame !== "undefined") {
      console.log("进来了");
      //@ts-ignore
      startGame();
    }
  }

  /**
   * Game end method when game is over, adapt for Mintegral channel.
   */
  gamClose() {
    console.log("game end");

    //@ts-ignore
    if (typeof onGameEnd !== "undefined") onGamClose();
  }

  /**
   * Set store url for redirect store action when user tap on CTA button.
   * Needed channel: Unity, Google
   * @param iosUrl: string
   * @param androidUrl: string
   */
  setStoreUrl(iosUrl: string, androidUrl: string) {
    console.log("set store url");
    //@ts-ignore
    if (typeof setStoreUrl !== "undefined") setStoreUrl(iosUrl, androidUrl);
  }
}

const ads = new AdsManager();
export default ads;